$NG.AllReady(function (page, { useValuesChange,useDataIndexChange,useUpdateRows,useUpdateRow }) {
    const mstform = $NG.getCmpApi("p_form_sybydsryc")
    const dgrid1 = $NG.getCmpApi("p_form_sybydsryc_d")
    const dgrid2 = $NG.getCmpApi("p_form_sybydsryc_d1")
    const month_init = 1453
    if(page.oType == 'add'){
        $NG.updateState((updater)=>{
            updater.data.p_form_sybydsryc.setProps({
                u_year:{
                    label:new Date().getFullYear(),
                    value:new Date().getFullYear()
                },
                u_month:{
                    label:`${new Date().getMonth()+1+1}月`,
                    value:month_init+(Number(new Date().getMonth()+1) || null)+1
                  }
            })
        })
    }
    useValuesChange(({args})=>{
        const map = args[0]
        getNewYearDetail()
    },"p_form_sybydsryc.syb")
    useUpdateRow(({args})=>{
        getYearPayPlanByPhidPc(args[0].phid_pc,mstform.getItem("u_year").getValue(),(data)=>{
            args[0].u_ndzbjh = data.u_bnhj
            args[0].u_ndzbtq = data.u_jynjh
            args[0].u_ndzbtb = (Number(data.u_jynjh) || 0)/(Number(data.u_bnhj) || 0)
        })
    },"p_form_sybydsryc_d")
    /**
     * 
     * 功能扩展
     * 
     * */
    function getNewYearDetail(){
        const syb = mstform.getItem("u_syb").getValue()
        const nd = mstform.getItem("u_year").getValue()
        if(!syb||!nd) return
        $NG.execServer("getNewYearDetail",{syb,nd},(res)=>{
            console.log(`获取新签明细`,res);
            if(res.count == 0) return 
            const _data = JSON.parse(res.data)
            const _tempArr = []
            _data.forEach(items=>{
                const item = items.extendObjects
                _tempArr.push({
                    u_qyzx:item.u_qyzx,
                    u_cpx:item.u_cpx,
                    phid_pc:item.phid_pc,
                    u_zt:item.u_zt,
                    u_qd_time:item.u_qdsj,
                    u_sl:item.u_sl,
                })
            })
            dgrid1.clearRows().then(()=>{
                dgrid1.addRows(_tempArr)
            })
        })
    }
    function getYearPayPlanByPhidPc(phid,nd,fun){
        $NG.execServer("getYearPayPlanByPhidPc",{phid_pc:phid,nd:nd},(res)=>{
            if(res.count == 0)return
            const _data = JSON.parse(res.data)[0].extendObjects
            fun(_data)
        })
    }
})  